package com.example.applicationeventdemo.listener;

import com.example.applicationeventdemo.pojo.UserArriveEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class UserArriveEventListener {

    @EventListener
    //调用异步线程处理,此时使用@order无法改变执行顺序
    @Async
    public void handleUserArriveEvent(UserArriveEvent event) {
        System.out.println(Thread.currentThread().getName() + "线程Event监听到用户达到事件，用户名: " + event.getUsername());
        // 实际业务
    }
}